import java.util.Arrays;

public class Solution {
    public static int[] func(int[] arr,int s){
        int left = 0;
        int right = arr.length-1;
        while (left<right){
            if (arr[left]+arr[right] > s){
                right--;
            } else if (arr[left]+arr[right] < s) {
                left++;
            }else{
                return new int[]{arr[left],arr[right]};
            }
        }
        //题目默认都会有结果，这里为了防止编译器报错
        return new int[]{arr[left],arr[right]};
    }
    public static void main(String[] args) {
        int[] arr = new int[] {10,26,30,31,41,60};
        int[] a = func(arr,40);
        System.out.println(Arrays.toString(a));
    }
}
